package interfaze;

import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import logic.Utilities;

/** Brick Breaker's Credits Panel class.
 * @author Team 1
 *
 */
@SuppressWarnings("serial")
public class BrickBreakerCreditsPanel extends JPanel implements ActionListener, MouseListener {
	
	SuperArcade2in1 window;							//The game's JFrame.
	JButton bBack = new JButton("Back");			//The back button.
	Font font;										//The font that is used for all the text labels and the button.
	private JLabel imageLabel = new JLabel();		//The image set in the middle of the screen.
	//The text located above the image.
	private JLabel lDirector = new JLabel("<html><center>Game Directed, Written and Designed by Jesus Sesma <br> Data Base Designed by Alejandro Perez <br> Powered by </html>",
			JLabel.CENTER);
	//The text located at the bottom of the image.
	private JLabel lStolen = new JLabel("All images have been stolen from Google©", JLabel.CENTER); //The text text located under the image.
	
	/** BrickBreakerCreditsPanel's constructor.
	 * @param window : The JFrame where this panel is added.
	 */
	public BrickBreakerCreditsPanel(SuperArcade2in1 window) {
		this.window = window;
		//sets the panel's layout to null in order to work with absolute coordinates. 
		this.setLayout(null);
		//Sets the panel's background color to black.
		this.setBackground(Color.BLACK);
		//Sets the font of all the text labels and buttons of the panel.
		font = new Font("Helvetica", Font.PLAIN, (int) (14 * window.xScale));
		
		//Sets the image between the two texts.
		Image image = Utilities.loadImage("res/crapcom.png");
		if(window.xScale != 1 || window.yScale != 1) {
			//if the window's resolution is not 1280x720 resizes the image proportionally.
			image = Utilities.resizeImage(window.xScale, window.yScale, "res/crapcom.png");
		}
		//Sets the image to label.
		imageLabel.setIcon(new ImageIcon(image));
		
		//Sets the components' location an characteristics.
		lDirector.setFont(font);
		lDirector.setForeground(Color.WHITE);
		lDirector.setBounds(0, Math.round(225 * window.xScale), window.width, Math.round(100 * window.yScale));
		lStolen.setFont(font);
		lStolen.setForeground(Color.WHITE);
		lStolen.setBounds(0, Math.round(400 * window.xScale), window.width, Math.round(100 * window.yScale));
		imageLabel.setBounds(Math.round((window.width / 2) - (image.getWidth(null) / 2)) ,
				Math.round((window.height /2) - (image.getHeight(null) / 2)), image.getWidth(null), image.getHeight(null));
		bBack.setBounds(Math.round(((window.width / 2) - (100 * window.xScale / 2))), Math.round(500 * window.yScale),
				Math.round(100 * window.xScale), Math.round(25 * window.yScale));
		bBack.setFont(font);
		
		//Adding components.
		this.add(bBack);
		this.add(lDirector);
		this.add(lStolen);
		this.add(imageLabel);

		//Adds listeners to the components.
		bBack.addActionListener(this);
		bBack.addMouseListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		//If the back button is pressed.
		if(e.getSource().equals(bBack)) {
			//Redirects to the brick breaker's main menu.
			window.add(new BrickBreakerMainMenuPanel(window));
			this.setVisible(false);
			window.remove(this);
		}
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		//If the mouse enters back button.
		if(e.getSource().equals(bBack)) {
			//Increases its size.
			Utilities.buttonEffect(bBack, 5, window.xScale, window.yScale);
		}
	}

	@Override
	public void mouseExited(MouseEvent e) {
		//If the mouse enters back button.
		if(e.getSource().equals(bBack)) {
			//Reduces its size.
			Utilities.buttonEffect(bBack, -5, window.xScale, window.yScale);
		}
	}

	@Override
	public void mousePressed(MouseEvent e) {
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		
	}
	
	@Override
	public void mouseClicked(MouseEvent e) {
		
	}
}
